package org.scorpio.account.controller;

import org.scorpio.account.pojo.bo.UserDetail;
import org.scorpio.account.pojo.vo.HttpResult;
import org.scorpio.account.service.IUserDetailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;

/**
 * <p>
 * Title:UserController
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author Li Enbo
 * @date 2017年11月8日上午9:37:16
 */
@RestController
@RequestMapping(value = "/", produces = "application/json;charset=UTF-8")
public class UserController {
	private Logger logger = LoggerFactory.getLogger(UserController.class);

	@Autowired
	IUserDetailService userDetailService;

	/**
	 * 
	 * @return
	 */
	@GetMapping(value = "user/{userId}")
	public HttpResult<UserDetail> getUserDetail(@PathVariable("userId") Integer userId) {
		System.err.println(userId);
		UserDetail user = userDetailService.selectById(userId);
		HttpResult<UserDetail> result = new HttpResult<UserDetail>(1001, "", user);
		return result;
	}

	/**
	 * 新增用户信息
	 * 
	 * @return
	 */
	@PostMapping(value = "user")
	public HttpResult<Long> saveUserDetail(UserDetail user) {
		logger.info("user{}", user);

		for (int i = 0; i < 100; i++) {
			UserDetail userDetail = new UserDetail();
			userDetail.setUsername("leibnolienbo11");
			userDetailService.insertAllColumn(userDetail);
		}

		return new HttpResult<Long>(1001, "", 1L);
	}

	/**
	 * 删除用户信息
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@DeleteMapping(value = "user")
	public HttpResult<Boolean> removeUserDetail() {
		Wrapper<UserDetail> eq = Condition.create().setSqlSelect("username").eq("username", "leibnolienbo");
		boolean delete = userDetailService.delete(eq);
		return new HttpResult<Boolean>(1001, "", delete);

	}

	/**
	 * 修改用户信息
	 * 
	 * @return
	 */
	@PutMapping(value = "user")
	public HttpResult<String> updateUserDetail() {
		return null;
	}
}
